<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>js操作多张图片切换练习</title>
    <style>
        body,ul,h3 { margin:0; padding:0; }
        li { list-style:none; }
        img { border:none; vertical-align:top; }
        body { font-size:12px; font-family:"微软雅黑"; }
        a{ text-decoration: none;}
        .clear { zoom:1; }
        .clear:after { content:''; display:block; clear:both; }
        .box{
            width: 700px;
            height: 400px;
            margin: 30px auto;
        }
        .warp div:nth-of-type(1){
            width: 300px;
            height: 400px;
            border: 20px solid #66FFCC;
            float: left;
        }
        .warp div:nth-of-type(2){
            width: 300px;
            height: 400px;
            border: 20px solid #66FFCC;
            float: right;
        }
        #img1, #img2{
            width: 300px;
            height: 350px;
            cursor: pointer;
        }
        p button{
            border: 1px solid #fefefe;
            border-radius: 5px;
        }
        .warp p{
            width: 300px;
            height: 30px;
            line-height: 30px;
            text-align: center;
        }
    </style>
    <script type="text/javascript">
        window.onload=function(){
            var srcArr1=['1.jpg','2.jpg','3.jpg','4.jpg'];
            var srcArr2=['5.jpg','6.jpg','7.jpg'];
            var oBtn1=document.getElementById("btn1");
            var oBtn2=document.getElementById("btn2");
            var oImg1=document.getElementById("img1");
            var oImg2=document.getElementById("img2");
            var oP1=oImg1.parentNode.getElementsByTagName('p')[0];
            var oP2=oImg2.parentNode.getElementsByTagName('p')[0];
            var num=0;
            var num_1=0;
            oImg1.src="img/mv/"+srcArr1[num];
            oP1 .innerHTML=num+1+"/"+srcArr1.length;
            oImg2.src="img/mv/"+srcArr2[num_1];
            oP2.innerHTML=num_1+1+"/"+srcArr2.length;
            oBtn2.onclick=function(){
                qh1();
                qh2();
            }
            oBtn1.onclick=function(){
                if(num==0){
                    num=srcArr1.length-1;
                }else{
                    num--;
                }
                oImg1.src="img/mv/"+srcArr1[num];
                oP1 .innerHTML=num+1+"/"+srcArr1.length;
                if(num_1==0){
                    num_1=srcArr2.length-1;
                }else{
                    num_1--;
                }
                oImg2.src="img/mv/"+srcArr2[num_1];
                oP2.innerHTML=num_1+1+"/"+srcArr2.length;
            }
            oImg1.onclick=function(){
                qh1();
            }
            oImg2.onclick=function(){
                qh2();
            }
            function qh1(){
                if(num==srcArr1.length-1){
                    num=0;
                }else{
                    num++;
                }
                oImg1.src="img/mv/"+srcArr1[num];
                oP1 .innerHTML=num+1+"/"+srcArr1.length;
            }
            function qh2(){
                if(num_1==srcArr2.length-1){
                    num_1=0;
                }else{
                    num_1++;
                }
                oImg2.src="img/mv/"+srcArr2[num_1];
                oP2.innerHTML=num_1+1+"/"+srcArr2.length;
            }
        }
    </script>
</head>
<body>
<div class="box">
    <p>
        <button id="btn1">上一组</button>
        <button id="btn2">下一组</button>
    </p>
    <div class="warp clear">
        <div>
            <img id="img1"/>
            <p></p>
        </div>
        <div>
            <img id="img2"/>
            <p></p>
        </div>
    </div>
</div>

</body>
</html>